package com.ph.irp.base.assistantmaterial.action;

import java.util.List;

import com.opensymphony.xwork2.ActionSupport;
import com.ph.irp.base.assistantmaterial.service.PBaseAssistantmaterialAreaService;
import com.ph.irp.model.PBaseAssistantmaterialArea;

/**
 * 辅助资料-区域Action
 * 
 * @author yan.jian@phinfoservices.com
 * 
 */
public class AssistantmaterialAreaAction extends ActionSupport {

	/**
	 * 
	 */
	private static final long serialVersionUID = 4943652058999687884L;
	private PBaseAssistantmaterialAreaService areaService;
	private PBaseAssistantmaterialArea area;

	private List<PBaseAssistantmaterialArea> areaList;
	private String[] rowlist;
	private String FORWARD;

	public PBaseAssistantmaterialAreaService getAreaService() {
		return areaService;
	}

	public void setAreaService(PBaseAssistantmaterialAreaService areaService) {
		this.areaService = areaService;
	}

	public PBaseAssistantmaterialArea getArea() {
		return area;
	}

	public void setArea(PBaseAssistantmaterialArea area) {
		this.area = area;
	}

	public List<PBaseAssistantmaterialArea> getAreaList() {
		return areaList;
	}

	public void setAreaList(List<PBaseAssistantmaterialArea> areaList) {
		this.areaList = areaList;
	}

	public String[] getRowlist() {
		return rowlist;
	}

	public void setRowlist(String[] rowlist) {
		this.rowlist = rowlist;
	}

	public String addArea() throws Throwable {
		areaService.addArea(area);
		FORWARD = "success";
		return FORWARD;
	}

	public String updateArea() throws Throwable {
		areaService.updateArea(area);
		FORWARD = "success";
		return FORWARD;
	}

	public String deleteAreas() throws Throwable {
		areaService.deleteArea(rowlist);
		FORWARD = "success";
		return FORWARD;
	}

	public String updateAreaInput() throws Throwable {
		int areaId = Integer.valueOf(rowlist[0]);
		area = areaService.getAreasById(areaId);
		FORWARD = "success";
		return FORWARD;
	}

	public String selectArea() throws Throwable {
		areaList = areaService.getAreas(area);
		area = null;
		FORWARD = "success";
		return FORWARD;
	}

	public String getAreas() throws Throwable {
		if (area == null)
			areaList = areaService.getAllAreas();
		else if (!area.getAreaCode().trim().equals("")
				&& !area.getAreaName().trim().equals(""))
			areaList = areaService.getAreasByCodeAndName(area.getAreaCode(), area
					.getAreaName());
		else if (!area.getAreaCode().trim().equals(""))
			areaList = areaService.getAreasByCode(area.getAreaCode());
		else if (!area.getAreaName().trim().equals(""))
			areaList = areaService.getAreasByName(area.getAreaName());
		else
			areaList = areaService.getAllAreas();
		area = null;
		FORWARD = "success";
		return FORWARD;
	}

	public String showAreaList() throws Throwable {
		area = null;
		return getAreas();
	}
}
